﻿using System.Collections.Generic;
using D2D2.SharedInterfaces.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace D2D2.Core.SpriteManager
{
    public class ChestManagerClient : BattleSpriteManager
    {
        private List<Chest> _chests = new List<Chest>();

        public Chest Add(Rectangle location, ChestObject chestObject)
        {
            Chest chest = new Chest(location, chestObject);
            chest.Init(chestObject.TotalVolume);

            _chests.Add(chest);

            return chest;
        }

        public bool Exist(ChestObject chestObject)
        {
            return _chests.Exists(c => c.Id == chestObject.Id);
        }

        public void Update(ChestObject chest)
        {
            Chest battleChest = _chests.Find(c => c.Id == chest.Id);
            battleChest.AddSnapshot(chest);
        }

        public override void Update(GameTime gameTime)
        {
            _chests.ForEach(m => m.Update(gameTime));
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            _chests.ForEach(c => c.Draw(spriteBatch));
        }
    }
}
